package com.leap.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leap.entity.Category;
import com.leap.mapper.CategoryMapper;
import com.leap.service.CategoryService;
import com.leap.utils.Const;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

     @Autowired
     private RedisTemplate redisTemplate;

    @Override
    public void loadCategoryName() {
        List<Category> categoryList = this.list();
        String key = Const.CATEGORY_NAME;
        Set keys = redisTemplate.keys(key);
        redisTemplate.delete(keys);
        redisTemplate.opsForList().rightPushAll(key, categoryList);
        redisTemplate.expire(key, 7, TimeUnit.DAYS);

    }
}
